package com.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;

public class NetReceiver extends BroadcastReceiver {
	private int first=0;

	@Override
	public void onReceive(Context context, Intent intent) {
		String action = intent.getAction();
		if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
			boolean isConnected = NetUtils.isNetworkConnected(context);
	        System.out.println("网络状态：" + isConnected);
	        System.out.println("wifi状态：" + NetUtils.isWifiConnected(context));
	        System.out.println("移动网络状态：" + NetUtils.isMobileConnected(context));
	        System.out.println("网络连接类型：" + NetUtils.getConnectedType(context));
	        if (isConnected) {
//	        	Toast.makeText(context, "已经连接网络", Toast.LENGTH_LONG).show();
	        } else {
//	        	Toast.makeText(context, "已经断开网络", Toast.LENGTH_LONG).show();
	        	if(first==0){
	        		first=1;
	        		CommonUtil.setNetDialog(context);// 设置网络
	        	}
	        	
	        }
		}
	}
	
}
